<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
      http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd">

    <changeSet id="001" author="alexander (bigtows) chapchuk">
        <createTable tableName="doctor_change">
            <column name="id" type="uuid">
                <constraints primaryKey="true"/>
            </column>
            <column name="doctor_id" type="uuid">
                <constraints nullable="false" unique="true"/>
            </column>
            <column name="rate" type="double"/>
            <column name="modality" type="varchar(30)"/>
            <column name="optional_modality" type="varchar(30) []"/>
            <column name="start_contract" type="date"/>
            <column name="end_contract" type="date"/>
            <column name="hours" type="double"/>
            <column name="work_days" type="int"/>
            <column name="weekend_days" type="int"/>
        </createTable>

        <createTable tableName="absence_schedule_request">
            <column name="id" type="uuid">
                <constraints primaryKey="true"/>
            </column>
            <column name="doctor_id" type="uuid">
                <constraints nullable="false"/>
            </column>
            <column name="start" type="datetime">
                <constraints nullable="false"/>
            </column>
            <column name="end" type="datetime">
                <constraints nullable="false"/>
            </column>
        </createTable>
    </changeSet>
    <changeSet id="002" author="alexander (bigtows) chapchuk">
        <renameTable oldTableName="absence_schedule_request" newTableName="absence_schedule"/>
    </changeSet>
    <changeSet id="003" author="alexander (bigtows) chapchuk">
        <modifyDataType tableName="absence_schedule" columnName="start" newDataType="date"/>
        <modifyDataType tableName="absence_schedule" columnName="end" newDataType="date"/>
    </changeSet>
    <changeSet id="004" author="alexander (bigtows) chapchuk">
        <dropColumn tableName="doctor_change" columnName="weekend_days"/>
        <dropColumn tableName="doctor_change" columnName="work_days"/>
        <addColumn tableName="doctor_change">
            <column name="work_days" type="varchar(30) []"/>
        </addColumn>
    </changeSet>
    <changeSet id="005" author="alexander (bigtows) chapchuk">
        <addColumn tableName="doctor_change">
            <column name="start_work_day" type="TIME WITHOUT TIME ZONE"/>
        </addColumn>
        <createTable tableName="doctor_work_schedule">
            <column name="id" type="uuid">
                <constraints primaryKey="true"/>
            </column>
            <column name="doctor_id" type="uuid">
                <constraints nullable="false"/>
            </column>
            <column name="hours" type="double"/>
            <column name="work_days" type="varchar(30) []"/>
            <column name="start_work_day" type="TIME WITHOUT TIME ZONE"/>
        </createTable>
    </changeSet>
    <changeSet id="006" author="alexander (bigtows) chapchuk">
        <addColumn tableName="doctor_change">
            <column name="created_date" type="datetime"/>
            <column name="modified_date" type="datetime"/>
        </addColumn>
        <sql>
            UPDATE doctor_change SET created_date = NOW(), modified_date = NOW();
        </sql>
        <addNotNullConstraint tableName="doctor_change" columnName="created_date"/>
        <addNotNullConstraint tableName="doctor_change" columnName="modified_date"/>


        <addColumn tableName="doctor_work_schedule">
            <column name="created_date" type="datetime"/>
            <column name="modified_date" type="datetime"/>
        </addColumn>
        <sql>
            UPDATE doctor_work_schedule SET created_date = NOW(), modified_date = NOW();
        </sql>
        <addNotNullConstraint tableName="doctor_work_schedule" columnName="created_date"/>
        <addNotNullConstraint tableName="doctor_work_schedule" columnName="modified_date"/>


        <addColumn tableName="absence_schedule">
            <column name="created_date" type="datetime"/>
            <column name="modified_date" type="datetime"/>
        </addColumn>
        <sql>
            UPDATE absence_schedule SET created_date = NOW(), modified_date = NOW();
        </sql>
        <addNotNullConstraint tableName="absence_schedule" columnName="created_date"/>
        <addNotNullConstraint tableName="absence_schedule" columnName="modified_date"/>
    </changeSet>
</databaseChangeLog>
